package com.elvin.httptask;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {

	private ArrayAdapter<ListCellData> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		adapter = new ArrayAdapter<ListCellData>(this, android.R.layout.simple_list_item_1);
		setListAdapter(adapter);

		adapter.add(new ListCellData(this, "Thread Test", new Intent(this, AtyThreadHttp.class)));
		adapter.add(new ListCellData(this, "AsyncTask Http Test", new Intent(this, AtyAsyncTaskHttp.class)));
		adapter.add(new ListCellData(this, "AsyncTask Json Test", new Intent(this, AtyAsyncTaskJson.class)));
		adapter.add(new ListCellData(this, "Submit Get Test", new Intent(this, AtySubmitDataByGet.class)));
		adapter.add(new ListCellData(this, "Submit Post Test", new Intent(this, AtySubmitDataByPost.class)));
		adapter.add(new ListCellData(this, "Advance Get", new Intent(this, AtyAdvanceAsyncHttp.class)));
		

	}




	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		ListCellData data = adapter.getItem(position);
		data.startActivity();
		super.onListItemClick(l, v, position, id);
	}

	public class ListCellData {

		public ListCellData(Context context, String controlName, Intent relatedIntent){
			this.controlName = controlName;
			this.context = context;
			this.relatedIntent = relatedIntent;
		}

		private String controlName = "";
		private Context context = null;
		private Intent relatedIntent = null;

		public String getControlName() {
			return controlName;
		}

		public Context getContext() {
			return context;
		}

		public Intent getRelatedIntent(){
			return relatedIntent;

		}

		public void startActivity(){
			getContext().startActivity(getRelatedIntent());
		}

		@Override
		public String toString(){
			return getControlName();
		}
	}

}
